// 标签页切换功能
document.addEventListener('DOMContentLoaded', function() {
    const tabButtons = document.querySelectorAll('.tab-button');
    const tabContents = document.querySelectorAll('.tab-content');

    tabButtons.forEach(button => {
        button.addEventListener('click', function() {
            // 移除所有按钮和内容的active类
            tabButtons.forEach(btn => btn.classList.remove('active'));
            tabContents.forEach(content => content.classList.remove('active'));
            
            // 为当前按钮和对应内容添加active类
            this.classList.add('active');
            const tabId = this.getAttribute('data-tab');
            document.getElementById(tabId).classList.add('active');
        });
    });

    // 导航栏高亮当前页面
    const currentPage = location.pathname.split('/').pop();
    const navLinks = document.querySelectorAll('.nav-links a');
    
    navLinks.forEach(link => {
        if (link.getAttribute('href') === currentPage) {
            link.classList.add('active');
        }
    });

    // 表单验证
    const contactForm = document.getElementById('contact-form');
    if (contactForm) {
        contactForm.addEventListener('submit', function(e) {
            e.preventDefault();
            let isValid = true;

            // 验证姓名
            const nameInput = document.getElementById('name');
            const nameError = nameInput.nextElementSibling;
            if (nameInput.value.trim() === '') {
                nameError.textContent = '请输入姓名';
                isValid = false;
            } else {
                nameError.textContent = '';
            }

            // 验证邮箱
            const emailInput = document.getElementById('email');
            const emailError = emailInput.nextElementSibling;
            const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
            if (!emailRegex.test(emailInput.value)) {
                emailError.textContent = '请输入有效的邮箱地址';
                isValid = false;
            } else {
                emailError.textContent = '';
            }

            // 验证电话
            const phoneInput = document.getElementById('phone');
            const phoneError = phoneInput.nextElementSibling;
            if (phoneInput.value && !/^\d{7,15}$/.test(phoneInput.value)) {
                phoneError.textContent = '请输入有效的电话号码';
                isValid = false;
            } else {
                phoneError.textContent = '';
            }

            // 验证留言内容
            const messageInput = document.getElementById('message');
            const messageError = messageInput.nextElementSibling;
            if (messageInput.value.trim() === '') {
                messageError.textContent = '请输入留言内容';
                isValid = false;
            } else {
                messageError.textContent = '';
            }

            if (isValid) {
                alert('留言提交成功！我们会尽快与您联系。');
                contactForm.reset();
            }
        });
    }
});